package com.joy.vo;

import com.joy.model.Assignment;
import com.joy.model.Course;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CourseDetailVO {

    private String className;

    private Integer classNum;

    private String teacherName;

    private List<TaskDetailVO> task = new ArrayList<>();

    public static CourseDetailVO from(Course course, List<Assignment> assignments) {
        if (course == null) {
            new CourseDetailVO();
        }
        CourseDetailVO courseDetailVO = new CourseDetailVO();
        courseDetailVO.setClassName(course.getCourseName());
        courseDetailVO.setClassNum(course.getClassNum());
        courseDetailVO.setTeacherName(course.getTeacherName());
        List<TaskDetailVO> tasks = new ArrayList<>();
        for (Assignment assignment : assignments) {
            tasks.add(TaskDetailVO.from(assignment));
        }
        courseDetailVO.setTask(tasks);
        return courseDetailVO;
    }

}
